<?

/**
* disect the real value of the serial number
*
* @param  integer $head
* @param  integer $tail
* @param  string  $serNum2nd
* @param  string  $serNum1st
* @param  integer $theRange
*
*/
function procSerNumRealValue(&$head,
                             &$tail,
                             &$serNum2nd,
                             &$serNum1st,
                             &$theRange){

  $length = $tail - $head;
  
  $range2 = substr($serNum2nd,
                   $head,
                   $length);
  
  $range1 = substr($serNum1st,
                   $head,
                   $length);
                   
  $theRange = $range2 - $range1 + _ARRAY_NUMBER;
}

/**
* Disect and increase the serial number
*
* @param  integer $head
* @param  integer $tail
* @param  string  $serNum1st
* @param  integer $incr
* @param  string  $theSerial
*
*/
function procSerNumber(&$head,
                       &$tail,
                       &$serNum1st,
                       &$incr,
                       &$theSerial){

  define('_DEFAULT_START'   , 0);

  if($incr > 0){
    
    $length = $tail - $head;
    
    $number = substr($serNum1st,
                     $head,
                     $length);
                     
    $number += $incr;
    
    /**
    * We have to process the zero leading
    * 
    */
    if(strlen($number) < $length){
      
      $number = addDigit2($length, (string) $number) . $number;
    }else{
      
      /* Do nothing */
    }
    
    $serial = substr($serNum1st,
                     _DEFAULT_START,
                     $head);

    $theSerial = $serial . $number;
  }else{
    
    $theSerial = $serNum1st;
  }
}
?>